<template>
    <view class="page_bill">
        <nav-bar title="订单记录"></nav-bar>
        <!-- 公共组件-每个页面必须引入 -->
        <public-module></public-module>
        <view class="tab_box">
            <view :class="{ active: type == '' }" @click="onTabSelect('')">全部</view>
            <view v-for="(item,index) of deliveryList" :key="index" :class="{ active: type == item.type }" @click="onTabSelect(item.type)">{{item.name}}</view>
        </view>
        <view class="support"></view>
        <mescroll-body ref="mescrollRef" height="-98" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
            <view class="bill_item" v-for="(item,index) of incomeBillList" :key="index">
                <view class="head_info">
                    <view class="order_type_box">
                        <view class="order_type">{{item.typeStr}}</view>
                    </view>
                    <text class="time">{{item.finishTimeStr}}</text>
                </view>
                <view class="content">
                    <view>
                        <text>订单编号：</text>
                        <text>{{item.orderNo}}</text>
                    </view>
                    <view>
                        <text>收入：</text>
                        <text>{{item.priceTotal}}</text>
                    </view>
                </view>
            </view>
        </mescroll-body>
    </view>
</template>

<script>
    import MescrollMixin from "@/components/common/mescroll-uni/mescroll-mixins.js";
    export default {
    	mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
        data() {
            return {
                type: "",
                downOption: {
                	auto: false //是否在初始化后,自动执行downCallback; 默认true
                },
                incomeBillList: [],
                deliveryList: []
            };
        },
        //第一次加载
        onLoad(e) {
            this.deliveryList = this.$base.deliveryList;
        },
        //页面显示
        onShow() {},
        //方法
        methods: {
            onTabSelect(type) {
                this.type = type;
                this.mescroll.triggerDownScroll();
            },
            /*下拉刷新的回调 */
            downCallback() {
            	//联网加载数据
            	this.loadData(1);
            },
            /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
            upCallback(page) {
            	//联网加载数据
            	this.loadData(page.num);
            },
            loadData(pageNo) {
                let httpData = {
                    pageNo: pageNo,
                    pageSize: 15,
                };
                if (this.type) {
                    httpData.orderType = this.type;
                }
                this.$http
                	.post('api/mime/wallet/v1/use_deducted_record', httpData,{
                		load:false
                	}).then(res => {
                		uni.stopPullDownRefresh();
                		//方法一(推荐): 后台接口有返回列表的总页数 totalPage
                		this.mescroll.endByPage(res.data.length, res.pages); //必传参数(当前页的数据个数, 总页数)
                		
                		if (pageNo == 1) {
                			this.incomeBillList = res.data;
                		} else {
                			this.incomeBillList = this.incomeBillList.concat(res.data);
                		}
                	}).catch(() => {
                		//联网失败, 结束加载
                		this.mescroll.endErr();
                	});
            },
            onPageJump(url) {
                uni.navigateTo({
                    url: url
                });
            }
        },
        //页面隐藏
        onHide() {},
        //页面卸载
        onUnload() {},
        //用户点击分享
        onShareAppMessage(e) {
            return this.wxShare();
        }
    };
</script>
<style lang="scss" scoped>
    @import "@/style/mixin.scss";

    .support {
        height: 120rpx;
    }

    // 导航栏
    .tab_box {
        display: flex;
        background-color: #fff;
        position: fixed;
        left: 0;
        width: 100%;
        justify-content: space-around;
        z-index: 2;
        border-top: 2rpx solid #f5f5f5;

        >view {
            padding: 30rpx;
            font-size: 28rpx;
            color: #333333;

            &.active {
                color: $themeColor;
                position: relative;

                &::after {
                    content: "";
                    position: absolute;
                    bottom: 0px;
                    left: 50%;
                    transform: translateX(-50%);
                    width: 40rpx;
                    height: 6rpx;
                    background-color: $themeColor;
                    border-radius: 3rpx;
                }
            }
        }
    }

    .page_bill {
        background-color: #f5f5f5;
        min-height: 100vh;
        padding: 0 30rpx 30rpx 30rpx;

        .bill_item {
            background-color: #ffffff;
            border-radius: 8rpx;
            padding: 0 30rpx;
            margin-bottom: 20rpx;

            .head_info {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 30rpx 0;
                border-bottom: 2rpx solid #e5e5e5;

                .order_type_box {
                    display: flex;
                    align-items: center;
                }

                .order_type {
                    font-size: 32rpx;
                    color: #333333;
                    margin-left: 14rpx;
                }

                .time {
                    font-size: 26rpx;
                    color: #333333;
                }
            }

            .content {
                padding: 20rpx 0;

                view {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    padding: 20rpx 0;
                    font-size: 28rpx;
                    color: #555555;
                }
            }
        }
    }
</style>
